# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/8 23:08
from PyQt5.Qt import *


class SB(QSpinBox):
	def textFromValue(self, p_int):
		print(p_int)
		return str(p_int)+"*"+str(p_int)


class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QSpinBox学习')
		self.resize(500, 500)
		self.setup_ui()

	def setup_ui(self):
		sb = SB(self)
		self.sb = sb
		sb.resize(100, 25)
		sb.move(100, 100)
		sb.valueChanged[str].connect(lambda val: print(type(val),val))
		sb.valueChanged.connect(lambda val: print(type(val),val))

		# self.最大值最小值()
		# self.数值循环()

		btn = QPushButton(self)
		btn.setText('测试按钮')
		btn.move(150, 150)
		btn.clicked.connect(lambda: self.设置和获取数值())



	def 设置和获取数值(self):
		# self.sb.setRange(0, 9)
		# self.sb.setValue(66)
		self.sb.setPrefix('飞虎')
		print(self.sb.value())
		print(self.sb.lineEdit().text())
		print(self.sb.text())

	def 显示的进制设置(self):
		print(self.sb.displayIntegerBase())
		self.sb.setDisplayIntegerBase(2)
		print(self.sb.displayIntegerBase())

	def 前缀后缀(self):
		# self.sb.setRange(1,12)
		# self.sb.setSuffix('月')
		self.sb.setRange(0, 6)
		self.sb.setPrefix('周')
		self.sb.setSpecialValueText('周日')

	def 设置步长(self):
		print(self.sb.singleStep())
		self.sb.setSingleStep(3)
		print(self.sb.singleStep())

	def 数值循环(self):
		print(self.sb.wrapping())
		self.sb.setWrapping(True)
		print(self.sb.wrapping())

	def 最大值最小值(self):
		# self.sb.setMaximum(180)
		# print(self.sb.maximum())
		#
		# self.sb.setMinimum(18)
		# print(self.sb.minimum())
		self.sb.setRange(18, 180)


if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())
